<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    // function fn({name,time})
    // {
    //     return new Promise((resolve, reject) => {
    //         setTimeout(function()
    //         {
    //             resolve(name);
    //         },time)
    //     })
    // }
    // let red_light = {name:"红灯",time:2000};
    // let green_light = {name:"绿灯",time:2000};
    // let yellow_light = {name:"黄灯",time:2000};
    // function deep()
    // {
    //     fn(red_light).then(resolve=>{
    //         console.log(resolve);
    //         return fn(green_light);
    //     }).then(resolve=>{
    //         console.log(resolve);
    //         return fn(yellow_light);
    //     }).then(resolve=>{
    //         console.log(resolve);
    //         deep();
    //     })
    // }
    // deep();






    // function fn({name,time})
    // {
    //     return new Promise((resolve, reject) => {
    //         setTimeout(()=>{
    //             resolve(name);
    //         },time)
    //     })
    // }
    // let red = {name:"红灯",time:2000};
    // let green = {name:"绿灯",time:2000};
    // let yellow = {name:"黄灯",time:2000};
    // function deep()
    // {
    //     fn(red).then(resolve=>{
    //         console.log(resolve);
    //         return fn(green);
    //     }).then(resolve=>{
    //         console.log(resolve);
    //         return fn(yellow)
    //     }).then(resolve=>{
    //         console.log(resolve);
    //         deep();
    //     })
    // }
    // deep();



    function fn({name,time})
    {
        return new Promise((resolve, reject) => {
            setTimeout(()=>{
                resolve(name);
            },time)
        })
    }
    let red = {name:"红灯",time:2000};
    let green = {name:"绿灯",time:1000};
    let yellow = {name:"黄灯",time:3000};
    async function deep()
    {
        await fn(red).then(resolve=>{
            console.log(resolve);
        });
        await fn(green).then(resolve=>{
            console.log(resolve);
        });
        await fn(yellow).then(resolve=>{
            console.log(resolve);
        });
        deep();
    }
    deep();
</script>
</html>